package com.example.active.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.scheduling.annotation.Scheduled;

import javax.jms.Queue;
import java.util.UUID;

/**
 * @author 朝花不迟暮
 * @version 1.0
 * @date 2020/9/18 13:08
 */
//@Component
public class QueueProducerBoot
{
    @Autowired
    private JmsMessagingTemplate jmsMessagingTemplate;

    @Autowired
    private Queue queue;

    public void productMessage(){
        jmsMessagingTemplate.convertAndSend(queue,"payload:"+ UUID.randomUUID().toString().substring(0,6));
    }

    @Scheduled(fixedDelay = 3000)
    public void productMessageScheduling() throws InterruptedException
    {
        jmsMessagingTemplate.convertAndSend(queue,"payload:"+ UUID.randomUUID().toString().substring(0,6));
        System.out.println("调用--->"+System.currentTimeMillis());
        /*while (true){
            jmsMessagingTemplate.convertAndSend(queue,"payload:"+ UUID.randomUUID().toString().substring(0,6));
            System.out.println("调用--->"+System.currentTimeMillis());
            Thread.sleep(3000);
        }*/
    }
}
